package cn.aresoft.framework.plugins.pagination.ibatis;

/**
 *  <p>Title: IbatisPage</p>
 *  <p>Description: IbatisPage</p>
 *  <p>Copyright: Copyright (c) 2009-9-1</p>
 *  <p>Company: 蓝色天空工作室</p>
 *
 * @author ShiGuanghui
 */

public class IbatisPage {
	
    private int count = 0; //查询的记录数，默认为0
    private int pageSize = 10;// 每页行数 默认10条
    private int pageCount = 0;// 页数 默认页数为0
    private int page = 1;//当前页 默认第一页

    private String resList; //查询的记录集
  
    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        if (pageSize != 0) {
            pageCount = count / pageSize;
            if (count % pageSize != 0) {
                pageCount++;
            }
        }
        this.count = count;
    }

    public String getResList() {
		return resList;
	}

	public void setResList(String resList) {
		this.resList = resList;
	}

	public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getPageCount() {
        return pageCount;
    }

    public void setPageCount(int pageCount) {
        this.pageCount = pageCount;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }
	
		
	public int getBegin() {
		return (this.page - 1) * this.pageSize;
	}

	public int getOffset() {
		return this.pageSize;
	}
	
	
	
	
	/**
	 * 显示用的分页信息
	 */
	public String getToolsMenu() {

		StringBuffer str = new StringBuffer("");
		int next, prev;
		prev = page - 1;
		next = page + 1;
		
		if (page > 1) {
			str.append("<a href=\"#\" onclick=\"document.forms[0].jumpPage.value=1;document.forms[0].submit();\">首页</a> ");
		} else {
			str.append("首页 ");
		}
		
		if (page > 1) {
			str.append("<a href=\"#\" onclick=\"document.forms[0].jumpPage.value="
							+ prev + ";document.forms[0].submit();\">上页</a> ");
		} else {
			str.append("上页 ");
		}
		if (page < pageCount) {
			str.append("<a href=\"#\" onclick=\"document.forms[0].jumpPage.value="
							+ next + ";document.forms[0].submit();\">下页</a> ");
		} else {
			str.append("下页 ");
		}
		if (pageCount > 1 && page != pageCount) {
			str.append("<a href=\"#\"  onclick=\"document.forms[0].jumpPage.value="
							+ pageCount
							+ ";document.forms[0].submit();\">末页</a>  ");
		} else {
			str.append("末页  ");
		}
		str.append(" 共" + count + "条记录");
		str.append("  每页<SELECT size=1 name=pagesize onchange=\"document.forms[0].jumpPage.value=1; document.forms[0].pageSize.value=this.value; document.forms[0].submit();\">");

		if (pageSize == 10) {
			str.append("<OPTION value=10 selected>10</OPTION>");
		} else {
			str.append("<OPTION value=10>10</OPTION>");
		}
		if (pageSize == 20) {
			str.append("<OPTION value=20 selected>20</OPTION>");
		} else {
			str.append("<OPTION value=20>20</OPTION>");
		}
		if (pageSize == 50) {
			str.append("<OPTION value=50 selected>50</OPTION>");
		} else {
			str.append("<OPTION value=50>50</OPTION>");
		}
		if (pageSize == 100) {
			str.append("<OPTION value=100 selected>100</OPTION>");
		} else {
			str.append("<OPTION value=100>100</OPTION>");
		}
		str.append("</SELECT>");
		str.append("条 分" + pageCount + "页显示 转到");
		str.append("<SELECT size=1 onchange=\"document.forms[0].jumpPage.value=this.value;document.forms[0].submit();\">");
		for (int i = 1; i < pageCount + 1; i++) {
			if (i == page) {
				str.append("<OPTION value=" + i + " selected>" + i
						+ "</OPTION>");
			} else {
				str.append("<OPTION value=" + i + ">" + i + "</OPTION>");
			}
		}
		str.append("</SELECT>页");
		str.append("<INPUT type=hidden  value=" + page
				+ " name=\"pages\" > ");
		str.append("<INPUT type=hidden  value=" + pageSize
				+ " name=\"pageSize\"> ");
		str.append("<INPUT type=hidden  value=\"\" name=\"jumpPage\"> ");
		
		return str.toString();

	}
}


